<template>
  <div class="app-container">
    <div v-show="!show.detailShow">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="名称" prop="fProjectname">
          <el-input placeholder="请选择名称"  clearable v-model="pdfname"></el-input>
        </el-form-item>

        <el-form-item label="类型" prop="fStatusname">
          <el-select v-model="queryParams.fStatusname" placeholder="请选择类型" clearable>
            <el-option
              v-for="dict in taskStatus"
              :key="dict"
              :label="dict"
              :value="dict"
            />
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['system:survey:add']"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['system:survey:edit']"
          >修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['system:survey:remove']"
          >删除</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-if="false"
          >导出</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="surveyList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="编号" align="center" prop="tucengid" />
        <el-table-column label="名称" align="center" prop="name" />
        <el-table-column label="类型" align="center" prop="type" />
        <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="200dp">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleDetails(scope.row)"
            >详情
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['system:survey:remove']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <taskDetail v-if="show.detailShow" ref="detail" :show="show"></taskDetail>
    <!-- 添加或修改调查列对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="名称" prop="sn">
          <el-input v-model="form.fWyUserid" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="类型" prop="bumen">
          <el-input v-model="form.fNyUserid" placeholder="请输入类型" />
        </el-form-item>
        <el-form-item label="地址" prop="xinghao">
          <el-input v-model="form.fXzqdm" type="textarea" placeholder="请输入地址URL" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSurveyStatus,listSurveyProjects,listSurvey, getSurvey, delSurvey, addSurvey, updateSurvey } from "@/api/survey/survey";
import taskDetail from '@/views/survey/task/taskDetail'
import { delFytb } from '@/api/economic/fytb'

export default {
  name: "pdfmanager",
  components: {taskDetail},
  data() {
    return {
      // 遮罩层
      addorUpdate:'add',
      loading: true,
      pdfname:null,
      projectNames:[],
      taskStatus:["通知公告"],
      show:{
        detailShow:false,
      },
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 调查列表格数据
      surveyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fLayerid: null,
        fProjectname:null,
        fWyUserid: null,
        fNyUserid: '通知公告',
        fXzqdm: null,
        fStatusid: null,
        fStatusname:null,
        fFeatureid: null,
        fSurveymedia: null,
        fSurveyprop: null,
        fSurveydesc: null,
        fReviewdesc: null,
        fSurveytime: null,
        fReviewtime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fFeatureid: [
          { required: true, message: "要素唯一标识不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
   // this.getProjectList();
  },
  methods: {

    getList() {
      let that=this;
      //  that.loading = true;
      that.surveyList =[
        {tucengid:"1",name:"2022年培训会议通知",type:"通知公告",url:"http://localhost:8095/catalogImage/pdf/2022tz.pdf",xinghao:"OnePlus",renyuan:"安达外业1",ruku:"2022-05-21",zhuangtai:"在用"},
        {tucengid:"2",name:"高标准农田建设统一上图入库数据汇交及质量要求",type:"通知公告",url:"http://localhost:8095/catalogImage/pdf/20221124143745strk.pdf",xinghao:"Hover",renyuan:"北林外业1",ruku:"2022-09-01",zhuangtai:"在用"},
        {tucengid:"3",name:"高标准农田建设统一上图入库数据要求",type:"通知公告",url:"http://localhost:8095/catalogImage/pdf/20221124143745data.pdf",xinghao:"HUAWEI",renyuan:"李伟",ruku:"2022-10-06",zhuangtai:"在用"},
      ];
      that.total = 3;
      that.loading = false;

    },
    getList2() {
      let that=this;
      //  that.loading = true;
      that.surveyList =[
        {tucengid:"2",name:"高标准农田建设统一上图入库数据汇交及质量要求",type:"通知公告",url:"http://localhost:8095/catalogImage/pdf/20221124143745strk.pdf",xinghao:"Hover",renyuan:"北林外业1",ruku:"2022-09-01",zhuangtai:"在用"},
        {tucengid:"3",name:"高标准农田建设统一上图入库数据要求",type:"通知公告",url:"http://localhost:8095/catalogImage/pdf/20221124143745data.pdf",xinghao:"HUAWEI",renyuan:"李伟",ruku:"2022-10-06",zhuangtai:"在用"},
      ];
      that.total = 3;
      that.loading = false;

    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fSurveyid: null,
        fLayerid: null,
        fWyUserid: null,
        fNyUserid: '通知公告',
        fXzqdm: null,
        fStatusid: null,
        fFeatureid: null,
        fSurveymedia: null,
        fSurveyprop: null,
        fSurveydesc: null,
        fReviewdesc: null,
        fSurveytime: null,
        fReviewtime: null
      };
      //  this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList2();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.fSurveyid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加文档信息";
      this.addorUpdate='add';
    },
    //查看项目详情
    handleDetails(row) {
      window.open(row.url)
    },
    /** 修改按钮操作 ，现在没有用*/
    handleUpdate(row) {
      let that=this;
      this.addorUpdate='update';
      this.open=true;
    },
    /** 提交按钮 */
    submitForm() {
      let that=this;
      this.getList();
      if( this.addorUpdate=='add'){
      that.surveyList.push({tucengid:"4",name:that.form.fWyUserid,type:"通知公告",url:"http://localhost:8095/catalogImage/pdf/2022tz.pdf",xinghao:"OnePlus",renyuan:"安达外业1",ruku:"2022-05-21",zhuangtai:"在用"})
      }
      else{
        that.surveyList.push({tucengid:"4",name:that.form.fWyUserid,type:"通知公告",url:"http://localhost:8095/catalogImage/pdf/2022tz.pdf",xinghao:"OnePlus",renyuan:"安达外业1",ruku:"2022-05-21",zhuangtai:"在用"})

      }
        this.open = false;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      let that=this;
      this.$confirm('是否确认删除此数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        that.getList();
      }).then(() => {
        this.msgSuccess('删除成功')
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('survey/export', {
        ...this.queryParams
      }, `survey_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
